home *** CD-ROM | disk | FTP | other *** search
- /*
-
- ButtonC
- Apre un gadget temporizzato, restituendo dei valori al CLI 0 o 5 a seconda
- di quale bottone e' stato cliccato
-
- (c) 1993 by Felice Murolo
- 2:335/206@fidonet - 39:102/5@amiganet
- +39 (0)89 756281 - Max BBS - 24h - HST
- Finito il 06.03.93
-
- Esempio d'uso da CLI
-
- Button "Carico il WorkBench ?" 5
-
- temporizza per 5 secondi la scritta specificata, in attesa di eventuali click
- di bottoni YES o NO
-
- Il codice ed il sorgente sono PD.
- */
-
- #include <intuition/intuition.h>
- #include <dos/dosextens.h>
-
- #define PRGNAME "Button"
- UBYTE *VERSION ="$VER: "PRGNAME" 1.0";
- #define DEFAULTGADTITLE PRGNAME" (c) 1993 by Felice Murolo"
- #define DEFAULTTEXT "No Operation text was specified"
- #define DEFAULTGADTEXT "Yes|No"
- #define DEFAULTSEC 3
-
- struct Library *IntuitionBase=NULL;
- struct Window *win=NULL;
- struct MsgPort *tp =NULL;
- struct timerequest *tim =NULL;
- struct EasyStruct eas =
- {
- sizeof(struct EasyStruct),
- 0,
- "",
- "",
- ""
- };
-
- char version[10];
-
- void CleanUp(char *,ULONG);
-
-
- /* Programma principale */
- main(int argc, char *argv[])
- {
- int ret=0,ibit=0,tbit=0,sec=DEFAULTSEC,signal=0;
-
- sprintf(version,"%s",VERSION+6+strlen(PRGNAME)+1);
-
- printf("%s v%s\n(c) 1993 by Felice Murolo\n\n",PRGNAME,version);
-
- eas.es_Title=DEFAULTGADTITLE;
- eas.es_TextFormat=DEFAULTTEXT;
- eas.es_GadgetFormat=DEFAULTGADTEXT;
- if (argc>1)
- {
- if (strncmp(argv[1],"?",1)==NULL)
- {
- printf("Usage: %s [gadget text (80 chars)] [numero secondi]\n",PRGNAME);
- CleanUp("",RETURN_OK);
- }
- argv[1][80]=0;
- eas.es_TextFormat=argv[1];
- if (argc>2)
- {
- ret=atoi(argv[2]);
- if (ret>0) sec=ret;
- }
- }
-
- if (IntuitionBase=(struct Library *)OpenLibrary("intuition.library",37))
- {
- if (tp=(struct MsgPort *)CreatePort(NULL,NULL))
- {
- tbit=1<<tp->mp_SigBit;
- if (tim=(struct timerequest *)CreateExtIO(tp,sizeof(struct timerequest)))
- {
- if (!OpenDevice(TIMERNAME,UNIT_VBLANK,tim,0))
- {
- if (win=(struct window *)BuildEasyRequest(NULL,&eas,NULL,NULL))
- {
- ibit=1<<win->UserPort->mp_SigBit;
- tim->tr_node.io_Command=TR_ADDREQUEST;
- tim->tr_time.tv_secs =sec;
- tim->tr_time.tv_micro =0;
- SendIO(tim);
- while ((ret=SysReqHandler(win,NULL,FALSE))==-2 && signal==0) signal=Wait(tbit | ibit);
- if (signal & tbit) GetMsg(tp);
- }
- else CleanUp("Can't open requester",RETURN_FAIL);
- }
- else CleanUp("Can't open timer.device",RETURN_FAIL);
- }
- else CleanUp("Cant create Timerequest",RETURN_FAIL);
- }
- else CleanUp("Can't open MsgPort",RETURN_FAIL);
- }
- else CleanUp("Can't open intuition.library",RETURN_FAIL);
- if (ret<0) ret=0;
- CleanUp("",ret*5);
- }
-
- /* Esce in modo pulito */
- void CleanUp(char *s,ULONG a)
- {
- if (win) FreeSysRequest(win);
- if (tim)
- {
- AbortIO(tim);
- if (tim->tr_node.io_Device) CloseDevice(tim);
- DeleteExtIO(tim);
- }
- if (tp) DeletePort(tp);
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- if (*s) printf("%s\n",s);
- exit(a);
- }
-
-